<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>注册页面</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" id="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="../../bower_components/bootstrap/dist/css/bootstrap.min.css"
          th:href="@{/LoginStyle/css/bootstrap.min.css}">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="../../bower_components/font-awesome/css/font-awesome.min.css"
          th:href="@{/LoginStyle/css/font-awesome.min.css}">
    <!-- Ionicons -->
    <link rel="stylesheet" href="../../bower_components/Ionicons/css/ionicons.min.css"
          th:href="@{/LoginStyle/css/ionicons.min.css}">
    <!-- Theme style -->
    <link rel="stylesheet" href="../../dist/css/AdminLTE.min.css" th:href="@{/LoginStyle/css/AdminLTE.css}">
    <!-- iCheck -->
    <link rel="stylesheet" href="../../plugins/iCheck/square/blue.css" th:href="@{/LoginStyle/css/blue.css}">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Google Font -->
    <link rel="stylesheet"
          href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body class="hold-transition register-page">
<div class="register-box">
    <div class="register-logo">
        <b>注册</b>
    </div>

    <div class="register-box-body">
        <form action="" method="post">
            <div class="form-group has-feedback">
                <input type="text" class="form-control" id="userName" placeholder="用户名">
                <span class="glyphicon glyphicon-user form-control-feedback"></span>
                <span id="userNameText" style="display: none;">用户名已存在！</span>
            </div>
            <div class="form-group has-feedback">
                <input type="email" class="form-control" id="userEmail" placeholder="邮箱">
                <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
            </div>
            <div class="form-group has-feedback">
                <input type="text" class="form-control" id="userPhone" placeholder="手机号码">
                <span class="glyphicon glyphicon-phone form-control-feedback"></span>
                <span id="userPhoneText" style="display: none;">手机号错误！</span>
            </div>
            <div class="form-group has-feedback">
                <input type="password" class="form-control" id="userPwd" placeholder="密码">
                <span class="glyphicon glyphicon-lock form-control-feedback"></span>
            </div>
            <div class="form-group has-feedback">
                <input type="password" class="form-control" id="userPwd2" placeholder="确认密码">
                <span class="glyphicon glyphicon-log-in form-control-feedback"></span>
                <span id="userPwd2Text" style="display: none;">密码不一致！</span>
            </div>
            <div class="form-group has-feedback">
                <input type="text" class="form-control" id="userSchool" placeholder="学院">
                <span class="glyphicon glyphicon-home form-control-feedback"></span>
            </div>
            <div class="form-group has-feedback">
                <input type="text" class="form-control" id="userMajor" placeholder="专业">
                <span class="glyphicon glyphicon-tasks form-control-feedback"></span>
            </div>
            <div class="row">
                <div class="col-xs-8">
                    <div class="checkbox icheck">
                        <label>
                            <input type="checkbox" id="check">我同意 <a href="#">《用户使用协议》</a>
                        </label>
                    </div>
                </div>
                <!-- /.col -->
                <div class="col-xs-4">
                    <button type="button" id="submit" class="btn btn-primary btn-block btn-flat">注册
                    </button>
                </div>
                <!-- /.col -->
            </div>
        </form>

        <a href="/User/Login" class="text-center">已拥有账户？</a>
    </div>
    <!-- /.form-box -->
</div>
<!-- /.register-box -->

<!-- jQuery 3 -->
<script src="../../bower_components/jquery/dist/jquery.min.js" th:src="@{/LoginStyle/js/jquery.min.js}"></script>
<!-- Bootstrap 3.3.7 -->
<script src="../../bower_components/bootstrap/dist/js/bootstrap.min.js"
        th:src="@{/LoginStyle/js/bootstrap.min.js}"></script>
<!-- iCheck -->
<script src="../../plugins/iCheck/icheck.min.js" th:src="@{/LoginStyle/js/icheck.min.js}"></script>
<script>
    /*checkbox点击样式*/
    $(function () {
        $('input').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' /* optional */
        });
    });
</script>

<script type="text/javascript">
    $(document).ready(function () {
        $("#userName").blur(function () {//检查用户名是否重复
            var userName = $("#userName").val();
            $.ajax({
                type: "post",
                url: "/User/Register/checkName",
                data: {userName: userName},
                success: function (data) {
                    console.log("用户名存在？" + data);
                    if (data == "yes") {
                        $("#userNameText").show();
                        $("#userNameText").css("color", "red");
                    } else $("#userNameText").hide();
                }
            });
        });

        var flag1 = true;//验证通过标志 true表示通过
        var flag2 = true;
        var flag3 = true;
        $("#userPhone").click(function () {
            $("#userPhone").blur(function () {
                var userPhone = $("#userPhone").val();
                if (userPhone.length < 11) {
                    flag1 = false;
                    $("#userPhoneText").show();
                    $("#userPhoneText").css("color", "red");
                } else {
                    $("#userPhoneText").hide();
                    flag1 = true;
                }
            });
        });


        $("#userPwd2").blur(function () {
            var userPwd = $("#userPwd").val();
            var userPwd2 = $("#userPwd2").val();
            if (userPwd == userPwd2) {
                $("#userPwd2Text").hide();
                flag3 = true;
            } else {
                $("#userPwd2Text").show();
                $("#userPwd2Text").css("color", "red");
                flag3 = false;
            }

        });


        $("#submit").click(function () {
            if (!$("#check").get(0).checked) {
                alert("未勾选《用户使用协议》!!")
                flag2 = false;
            } else
                flag2 = true;
            var userName = $("#userName").val();
            var userEmail = $("#userEmail").val();
            var userPhone = $("#userPhone").val();
            var userPwd = $("#userPwd").val();
            var userSchool = $("#userSchool").val();
            var userMajor = $("#userMajor").val();
            if (flag1 && flag2 && flag3) {
                $.ajax({
                    type: "post",
                    url: "/User/Register/data",
                    data: {
                        userName: userName,
                        userEmail: userEmail,
                        userPhone: userPhone,
                        userPwd: userPwd,
                        userSchool:userSchool,
                        userMajor:userMajor
                    },
                    success: function (data) {
                        console.log("注册成功？" + data);
                        if (data == "yes")
                            window.location.href = "/User/Login";
                    }
                });
            }
        });


        // $('form').submit(function CheckPost() {
        //     // alert(flag1 + "," + flag2+","+flag3);
        //     return flag1 && flag2 && flag3;
        // });
    });
</script>
</body>
</html>
